package cn.ito.zjgsu.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.ito.zjgsu.domain.Authority;
import cn.ito.zjgsu.domain.AuthorityExample;
import cn.ito.zjgsu.domain.wrapper.AuthorityWrapper;
import cn.ito.zjgsu.mapping.AuthorityMapper;
import cn.ito.zjgsu.service.AuthorityService;

@Service
@Transactional
public class AuthorityServiceImpl implements AuthorityService {
	
	@Resource
	private AuthorityMapper authorityMapper;
	
	public List<Authority> findAllAuthorities(){
		AuthorityExample authorityExample =  new AuthorityExample();
		return authorityMapper.selectByExample(authorityExample);		
	}

	@Override
	public List<AuthorityWrapper> queryPermissionsByPids(int[] permissions) {
		AuthorityExample authorityExample = new AuthorityExample();
		List<Integer> pids = new ArrayList<Integer>();
		for(Integer i : permissions){
			pids.add(i);
		}
		authorityExample.or().andAuthorityIdIn(pids);
		List<Authority> authorities = authorityMapper.selectByExample(authorityExample);		
		return AuthorityWrapper.WrapAuthority(authorities);
	}

	@Override
	public List<AuthorityWrapper> findAllWrappedAuthorities() {	
		return AuthorityWrapper.WrapAuthority(findAllAuthorities());
	}
}
